import router from './index';

router.beforeEach((to, from, next) => {
  const token = localStorage.getItem('token');
  if (to.matched.some((record) => record.meta.requiresAuth)) {
    if (!token) {
      return next({
        name: 'login',
      });
    }
  } else if (to.name === 'login' && token) {
    return next({
      name: 'dashboard',
    });
  }
  next();
});